<?php
class DbModel{
	//protected static $cache;
	protected $db;//数据库连接句柄

	public function __construct(){
      if(!$this->db){
          $this->db = YYKPDO::create();
      }
  }
    
	public function __call($name, $arguments) {
		E('DbModel方法[' . $name . ']不存在');
	}

	public function backupSql($tab, $where){
		$db = $this->db;
		$row = $db->table($tab)->where($where)->select();
		if ($row) {
			$sql = "insert into `{$tab}` values \n";
			foreach ($row as $key => $item) {
				$sql .= "(";
				foreach ($item as $value) {
					$sql .= "'{$value}',";
				}
				$sql = trim($sql, ',');
				$sql .= "),\n";
			}
			$sql = trim($sql, ",\n");
			return $sql;
		}
		else{
			return false;
		}
	}
}